package proteus.servlets;

import java.io.IOException;
import java.util.Collection;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import proteus.excepcion.DAOExcepcion;
import proteus.modelo.Local;
import proteus.negocio.LocalNegocio;

/**
 * Servlet implementation class GuardarLocalServlet
 */
@WebServlet("/GuardarLocalServlet")
public class GuardarLocalServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public GuardarLocalServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		
		
		
		try
		{
			
			String _NoLocal=request.getParameter("txtNom");
			String _TxDireccion=request.getParameter("txtDireccion");
			String _NoDistrito=request.getParameter("txtDistrito");
			String _TxDireccionGoogle=request.getParameter("localURL");
			String _NuTelefono=request.getParameter("txtNroCel");
			Integer _CoPersona=Integer.parseInt(request.getParameter("cboDueno"));
			
			LocalNegocio neg=new LocalNegocio();
			
			neg.insertarLocal(_NoLocal, _TxDireccion, _NoDistrito, _TxDireccionGoogle, _NuTelefono, _CoPersona);
			
			
			
//			Collection<Local> lista = neg.listarLocales();
//			request.setAttribute("locales", lista);
//			
//			RequestDispatcher rd = request.getRequestDispatcher("ListadoLocal.jsp");
//			rd.forward(request, response);

		}
		catch(DAOExcepcion e){
			request.setAttribute("msgerror", e.getMessage());
			
			
		}
		
		request.setAttribute("msg", "Se registro correctamente");
		RequestDispatcher rd=request.getRequestDispatcher("ConfirmacionLocal.jsp");
		
		rd.forward(request, response);
		
		
		
		
		//request.setAttribute("visitas", "Se registro correctamente");
		//RequestDispatcher rd=request.getRequestDispatcher("ListadoLocal.jsp");
		//rd.forward(request, response);
		
	}

}
